import { E_MsgCode } from "../defs/proto/E_MsgCode";
import { CDBuyTimeLimit } from "../excel/CDBuyTimeLimit";
import { Player } from "../struct/Player";



/**
 * 数据-限购次数
 */
export abstract class SDBuyTimeLimit {


    /**不可购买时的参数 */
    public static canNotBuyParam: any = null;


    /**
     * 是否可购买
     * @param player 
     * @param limitId 
     * @param buyTimes 
     * @returns 
     */
    public static checkBuyStatus(player: Player, limitId: number, buyTimes: number): number {
        const config = CDBuyTimeLimit.getData(limitId);
        if (config) {
            const sell = player.shopManager.getSell(config.limitType);
            const buyed = sell.getCount(limitId);
            if (buyed + buyTimes > config.times) {
                this.canNotBuyParam = config.times;
                return E_MsgCode.ShopSellTimesLimit;
            }
        }
        return 0;
    }


}
